package com.kitty.game.equip.service;


import com.kitty.common.utils.SpringUtils;
import com.kitty.game.activity.model.product.ActivityType;
import com.kitty.game.config.Equip;
import com.kitty.game.config.NPC;
import com.kitty.game.confirm.model.MSDRConfirmOnekey;
import com.kitty.game.equip.EquipDataPool;
import com.kitty.game.equip.model.EquipBox;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.npc.NpcDataPool;
import com.kitty.game.npc.message.RespNpcContent;
import com.kitty.game.npc.model.NpcButton;
import com.kitty.game.role.model.Role;
import com.kitty.game.team.message.RespConfirm;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.Map;

import static com.kitty.game.npc.model.NpcButton.miaoshou_daoren_huishou;

@Service
@Slf4j
public class MSDRService {
    @Autowired
    EquipService equipService;


    public void init() {
        NpcDataPool.npcButtonHandlers.put(NpcButton.miaoshou_daoren_huishou.getKey(), (npcButtonParam -> SpringUtils.getBean(MSDRService.class).huishou(npcButtonParam.getRole(), npcButtonParam.getMsg())));
    }

    private void huishou(Role role, String msg) {

    }

    public void onekey(Role role, String msg) {
        role.setConfirm(new MSDRConfirmOnekey(msg));
        msg = "请把#R贵重物品#n提前存放到仓库,点击确认会清理掉背包内#R所有物品#n，请确认是否#R" + "一键清理背包" + "#n？";
        RespConfirm respConfirm = new RespConfirm();
        respConfirm.setTips(msg);
        MessagePusher.pushMessage(role, respConfirm);
    }

    public void queryNum(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        StringBuffer sb = new StringBuffer();
        int tianxingSum = ActivityType.XING_GUAN_tian.getTotalCount();
        int tianxing = role.getActivity().getFinishCounts().getInt(ActivityType.XING_GUAN_tian.getActivityId(), 0);
        int dixingSum = ActivityType.XING_GUAN_di.getTotalCount();
        int dixing = role.getActivity().getFinishCounts().getInt(ActivityType.XING_GUAN_di.getActivityId(), 0);
        int shangguSum = ActivityType.SEAL_BOSS.getTotalCount();
        int shanggu = role.getActivity().getFinishCounts().getInt(ActivityType.SEAL_BOSS.getActivityId(), 0);
        int zhanshenSum = ActivityType.zhansheng_ACTIVTY.getTotalCount();
        int zhanshen = role.getActivity().getFinishCounts().getInt(ActivityType.zhansheng_ACTIVTY.getActivityId(), 0);
        int chaojiSum = ActivityType.SUPER_BOSS.getTotalCount();
        int chaoji = role.getActivity().getFinishCounts().getInt(ActivityType.SUPER_BOSS.getActivityId(), 0);


        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        respNpcContent.setContent(SpringUtils.getBean(NewChargeActivityService.class).getShow(role));
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    // TODO::临时允许清理所以装备和首饰
    public void besure(Role role) {
        log.error("一键清理背包={}={}", role.getRoleId(), role.getName());
        EquipBox equipBox = role.getEquipBox();
        Iterator<Map.Entry<Integer, RoleEquip>> iterator = equipBox.getEquips().entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, RoleEquip> equipEntry = iterator.next();
            // 修改法宝id
            RoleEquip roleEquip = equipEntry.getValue();
            if (roleEquip.getPosition() >= 200) {
                continue;
            }
            if (roleEquip.getPosition() < 41) {
                continue;
            }
            // 改4不能删
//            if (roleEquip.queryUpgradeLevel() >= 4) {
//                continue;
//            }
            //首饰80级以上不能删
//            Equip equip = EquipDataPool.getByName(roleEquip.getName());
//            if (equip != null && (equip.getPosition() == 4 || equip.getPosition() == 5 || equip.getPosition() == 6) && equip.getReq_level() >= 80) {
//                continue;
//            }
            //法宝不能删
//            if (roleEquip.getType().equals("法宝")) {
//                continue;
//            }
            //魂器不能删
//            if (roleEquip.getType().startsWith("魂器")) {
//                continue;
//            }
            //女娲石不删
//            if (roleEquip.getName().contains("女娲石")) {
//                continue;
//            }
            log.error("一键清理背包=={}=={}=={}=={}", role.getRoleId(), roleEquip.getName(), roleEquip.getId(), roleEquip.queryUpgradeLevel());
            equipService.delRoleEquip(roleEquip, role);
        }
    }

    public String point(Role role) {
        return "[" + miaoshou_daoren_huishou.getKey() + "]";
    }
}
